package com.es.code.user.service.impl;

import com.es.code.annotation.LogAround;
import com.es.code.commons.ResultConstant;
import com.es.code.commons.ResultData;
import com.es.code.user.enity.ESUser;
import com.es.code.user.service.EsUserService;
import com.es.code.user.vo.UserVo;
import com.es.code.utils.ElasticSearchUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author jichf
 * @Description
 * @create 2021-11-04 9:47
 */

@Service
public class EsUserServiceImpl implements EsUserService {

    @Autowired
    private ElasticSearchUtils elasticSearchUtils;

    /**
     * 创建索引
     *
     * @return
     */
    @Override
    @LogAround("创建 es_user 索引")
    public ResultData createEsIndex() {
        boolean bool = elasticSearchUtils.createIndex(true, ESUser.class, null);
        if (bool) {
            return new ResultData(ResultConstant.SUCCESS, "创建索引成功");
        } else {
            return new ResultData(ResultConstant.FAILED, "创建索引失败");
        }

    }

    /**
     * 删除索引
     *
     * @return
     */
    @Override
    public ResultData deleteEsIndex() {
        boolean delete = elasticSearchUtils.deleteIndex(true, ESUser.class, null);
        if (delete) {
            return new ResultData(ResultConstant.SUCCESS, "删除索引失败");
        } else {
            return new ResultData(ResultConstant.FAILED, " 删除索引失败");
        }

    }

    /**
     * 是否存在索引
     *
     * @return
     */
    @Override
    public ResultData existEsIndex() {
        boolean exists = elasticSearchUtils.existIndex(true, ESUser.class, null);
        return new ResultData(ResultConstant.SUCCESS, exists);
    }

    /**
     * 保存一个文档
     *
     * @param userVo
     * @return
     */
    @Override
    public ResultData saveEsDoc(UserVo userVo) {
        return null;
    }

    /**
     * 根据名称获取文档
     *
     * @param name
     * @return
     */
    @Override
    public ResultData queryByName(String name) {
        return null;
    }

    /**
     * 根据id获取文档
     *
     * @param id
     * @return
     */
    @Override
    public ResultData queryById(Long id) {
        return null;
    }

    /**
     * 根据某些条件查询
     *
     * @param userVo
     * @return
     */
    @Override
    public ResultData queryByUser(UserVo userVo) {
        return null;
    }

    /**
     * 高亮查询
     *
     * @param fields 高亮查询的字段
     * @return
     */
    @Override
    public ResultData queryHighLight(String... fields) {
        return null;
    }
}
